package vn.ikame.android.boojtran.truyenbua.download;

import vn.ikame.android.boojtran.truyenbua.ListItem;
import vn.ikame.android.boojtran.truyenbua.logic.ImageManager;
import vn.ikame.android.boojtran.truyenbua.utility.StorageUtils;

public class DownloadPic implements IDownloadHandler {
	IDownloadPicHandler listener;
	String imageUrl;

	public DownloadPic(IDownloadPicHandler listener) {
		this.listener = listener;
	}

	public void download(int index, String link) {
		imageUrl = link;
		Download download = new Download(this);
		download.DownloadFromUrl(index, link,
				StorageUtils.getPathFileSaveFromUrl(ListItem.menu, link));
	}

	public void download(String link) {
		imageUrl = link;
		Download download = new Download(this);
		download.DownloadFromUrl(link,
				StorageUtils.getPathFileSaveFromUrl(ListItem.menu, link));
	}

	@Override
	public void onDownloadFinish(int index, String path) {
		if (listener != null) {
			listener.onDownloadFinish(index);
		}
		ImageManager.get().finishDownload(path);
	}

	@Override
	public void onDownloadError(int index, String path) {
		if (listener != null)
			listener.onDownloadError(index);
	}

	@Override
	public void downloadProgress(int progress) {
		if (listener != null)
			listener.downloadProgress(progress);
	}

}
